//
//  UIBarButton+Extension.swift
//  学习微博
//
//  Created by zengyu on 2017/9/13.
//  Copyright © 2017年 weibo. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontsize: 字体大小，默认16
    ///   - isBack: 判断是否为返回按钮
    ///   - target: target
    ///   - action: 触发时间
    convenience init(title: String, fontsize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false ) {
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontsize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack{
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //selft.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }
}
